/*
 * @Author: CodeHare
 * @Date: 2023-09-19 18:46:23
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-10 10:09:11
 * @Description: EMS详情页面
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/model/device_model.dart';
import 'package:yt_devops/pages/devices/device_tab/model/device_item_model.dart';
import 'package:yt_devops/resources/resources.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/routers/router_path.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/enums.dart';
import '../../../utils/device_util.dart';

import '../../../components/detail_grid_widget.dart';
import 'self_develop_ems_detail_controller.dart';

class SelfDevelopEmsDetailPage
    extends GetWidget<SelfDevelopEmsDetailController> {
  final DeviceModel? deviceModel;
  const SelfDevelopEmsDetailPage({Key? key, this.deviceModel})
      : super(key: key);

  @override
  SelfDevelopEmsDetailController get controller =>
      Get.put<SelfDevelopEmsDetailController>(SelfDevelopEmsDetailController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget.withRightActions(
        controller.title,
        actions: <Widget>[
          Visibility(
            visible: controller.judgeEsDeviceIsMasterOrSalve(deviceModel),
            child: GestureDetector(
              onTap: () => controller.operateEms(),
              child: Padding(
                padding: EdgeInsets.only(right: 16.w),
                child: Image.asset(
                  ImageAssets.iconEmsDetailAction,
                  width: 20.w,
                  height: 20.h,
                ),
              ),
            ),
          ),
        ],
      ),
      body: GetBuilder<SelfDevelopEmsDetailController>(initState: (state) {
        controller.initData(deviceModel);
      }, builder: (_) {
        return SafeArea(
          child: Stack(
            children: <Widget>[
              ListView(
                  physics: const NeverScrollableScrollPhysics(),
                  shrinkWrap: false,
                  children: [
                    if (controller.groupItems != null)
                      DeviceUtil.blockContainer(
                        DetailGridWidget(
                          title: controller.groupItems!.title,
                          items: [
                            ...controller.groupItems!.items,
                            ...controller.emsItems
                          ],
                          dataSource: controller.dataSource,
                          isLightTtext:
                              controller.connectStatus != ConnectStatusType.on,
                          isSingleRow: true,
                        ),
                      )
                  ]),
              Positioned(
                right: 0,
                top: 0,
                child: Visibility(
                  visible: controller.isOperateEms,
                  child: GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: controller.operateEms,
                    child: SizedBox(
                      height: ScreenUtil().screenHeight,
                      width: ScreenUtil().screenWidth,
                      child: Container(
                        height: 120.h,
                        width: 139.w,
                        margin: EdgeInsets.only(
                            left: ScreenUtil().screenWidth - 149.w,
                            bottom: ScreenUtil().screenHeight - 120.h),
                        decoration: const BoxDecoration(
                          image: DecorationImage(
                            alignment: Alignment.topCenter,
                            image: AssetImage(
                              ImageAssets.siteAccessBg,
                            ),
                          ),
                        ),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Gaps.vGap25,
                            GestureDetector(
                                behavior: HitTestBehavior.opaque,
                                child: Row(
                                  children: [
                                    Container(
                                      margin: EdgeInsets.only(
                                        left: 24.w,
                                        top: 5.h,
                                      ),
                                      child: Image.asset(
                                        ImageAssets.iconRemoteControl,
                                        width: 20.w,
                                        height: 20.w,
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(
                                        left: 5.w,
                                        top: 3.h,
                                      ),
                                      child: Text(
                                        'siteMonitor.remoteControl'.tr, //远程控制
                                        style: ytTextStyle(
                                          fontSize: 14.sp,
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                                onTap: () {
                                  controller.goControlRomote();
                                }),
                            Gaps.vGap10,
                            Container(
                              color: Colour.dividerColor,
                              margin: EdgeInsets.only(
                                left: 21.w,
                                right: 21.w,
                              ),
                              height: 1.h,
                            ),
                            Gaps.vGap10,
                            GestureDetector(
                              behavior: HitTestBehavior.opaque,
                              child: Row(
                                children: [
                                  Container(
                                    margin: EdgeInsets.only(left: 24.w),
                                    child: Image.asset(
                                      ImageAssets.iconSetting,
                                      width: 20.w,
                                      height: 20.w,
                                    ),
                                  ),
                                  Container(
                                    margin: EdgeInsets.only(
                                      left: 5.w,
                                      bottom: 3.h,
                                    ),
                                    child: Text(
                                      ResKey.deviceParameterSetting.tr, //参数设置
                                      style: ytTextStyle(
                                        fontSize: 14.sp,
                                      ),
                                    ),
                                  )
                                ],
                              ),
                              onTap: () {
                                controller.goSetParams();
                              },
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      }),
    );
  }
}
